<template>
  <div class="section_common">
    <div class="main">
      <el-form ref="form" label-width="100px">

        <el-form-item label="所属仓库" required>
          <el-radio v-model="area" label="1">东莞仓</el-radio>
          <el-radio v-model="area" label="2">上雪仓</el-radio>
        </el-form-item>

        <el-form-item label="所属区域" required>
          <el-radio v-model="type" label="仓库现场">仓库现场</el-radio>
          <el-radio v-model="type" label="办公用品">办公用品</el-radio>
          <el-radio v-model="type" label="宿舍">宿舍</el-radio>
        </el-form-item>


        <el-form-item label="部门/房号" required>
          <el-input v-model="dept" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="维修物品名称" required>
          <el-input v-model="goods" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="故障原因" required>
          <el-input v-model="description" size="mini"></el-input>
        </el-form-item>

        <van-steps direction="vertical" :active="active" active-icon="checked" active-color="#38f">
          <p style="font-size:16px;font-weight: 900;margin-bottom: -10px;">审批人</p>
          <van-step v-show="oneShow">
            <!--<p style="font-size:16px;font-weight: 900">组长</p>-->
            <van-image v-for="(item,index) in oneLd" :key="index" :src="item.avatar" width="60" height="60" style="margin-right: 20px;margin-bottom: 20px">
              <p style="font-size: 10px ;justify-content: center">{{item.name}}</p>
            </van-image>
          </van-step>
          <van-step v-show="twoShow">
            <!--<p style="font-size:16px;font-weight: 900">主管</p>-->
            <van-image v-for="(item,index) in twoLd" :key="index" :src="item.avatar" width="60" height="60" style="margin-right: 20px;margin-bottom: 20px">
              <p style="font-size: 10px ;justify-content: center">{{item.name}}</p>
            </van-image>
          </van-step>
          <van-step v-show="fourShow">

            <van-image v-for="(item,index) in fourLd" :key="index" :src="item.avatar" width="60" height="60" style="margin-right: 20px;margin-bottom: 20px">
              <p style="font-size: 10px ;justify-content: center">{{item.name}}</p>
            </van-image>
          </van-step>
          <van-step v-show="threeShow">
            <p style="font-size:16px;font-weight: 900">抄送人</p>
            <!--<p style="font-size:16px;font-weight: 900">指定审批人</p>-->
            <van-image v-for="(item,index) in threeLd" :key="index" :src="item.avatar" width="60" height="60" style="margin-right: 20px;margin-bottom: 20px">
              <p style="font-size: 10px ;justify-content: center">{{item.name}}</p>
            </van-image>
          </van-step>

        </van-steps>

        <van-dialog v-model="show" show-cancel-button :before-close="chargeBtn">
          <!-- 输入框 -->
        <!--  <el-input v-model="reason" rows="1" autosize label="驳回原因" type="textarea" placeholder="请输入驳回原因"/>
         -->
          <el-form-item label="驳回原因" required>
            <el-input v-model="reason" size="mini"></el-input>
          </el-form-item>
        </van-dialog>

        <el-form-item>
          <el-button id="isAgree" v-show="showtg" v-bind:disabled="isShow" type="primary" size="mini" @click="submitAgree">{{message}}</el-button>
          <el-button id="isNotAgree" v-show="showbh" v-bind:disabled="isShow" type="warning" size="mini" @click="submitNotAgree">{{message1}}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import Vue from 'vue';
  import { Image as VanImage ,Toast,Picker,Popup,Dialog} from 'vant';
  Vue.use(Picker);
  Vue.use(Popup);
  Vue.use(VanImage);
  Vue.use(Dialog)
export default {
  data() {
    return {
      id:"",
      area:"",
      type:"",
      dept:"",
      goods:"",
      description:"",
      reason:"无",
      applicant:"",

      nowUser:"",
      title: "物资维修详情",

      addMaintainApply: '/mobiles/addMaintainApply',
      isShow:false,
      message:"通过",
      message1:"驳回",
      show:false,

      showtg:true,
      showbh:true,

      active:"-1",//步骤索引,从0开始
      oneShow:false,//审批是否显示
      oneLd:[],
      twoShow:false,
      twoLd:[],
      threeShow:false,
      threeLd:[],
      fourShow:false,
      fourLd:[],

    };
  },
  created() {
    this.nowUser=JSON.parse(localStorage.getItem('userInfo')).userId;
    this.id= this.$route.params.id;

    this.getMaintainInfo();
    //this.getLd();//查询审批流程中的上级领导
  },
  methods: {

    //查找对应用户的上级领导进行审批
    getLd(){
      this.$https.post('/mobiles/getSpld',{
        nowUser:this.applicant,
      }).then((res)=>{
        if (res.data.data.ld1.length>0){
          this.oneShow=true;
          this.oneLd=res.data.data.ld1;
        }
        if (res.data.data.ld2.length>0){
          this.twoShow=true;
          this.twoLd=res.data.data.ld2;
        }
        if (res.data.data.ld3.length>0){
          this.threeShow=true;
          this.threeLd=res.data.data.ld3;
        }
        if (res.data.data.ld4.length>0){
          this.fourShow=true;
          this.fourLd=res.data.data.ld4;
        }
      }).catch(err => {
        console.log(err);
      })
    },

    //根据入职管理的id找到相对应的入职管理详情
    getMaintainInfo(){
      this.$https.post('/mobiles/getMaintainInfo',{
        nowUser:this.nowUser,
        id:this.id
      }).then((res)=>{
        this.applicant=res.data.data.applicant;
        this.getLd();//查询审批流程中的上级领导
        this.active=res.data.data.agree-1;
        // if (res.data.data.cs.length>0){
        //   this.fourShow=true;
        //   this.fourLd=res.data.data.cs;
          if (res.data.data.result==="已通过"){
            this.active=this.active+1;
          }
        // }
        this.area=res.data.data.area;
        this.type=res.data.data.type;
        this.dept=res.data.data.dept;
        this.goods=res.data.data.goods;
        this.description=res.data.data.description;
        if (res.data.data.submit=='0'){
          this.isShow=true;
          this.message="已审核";
          this.showbh=false;
        }else if (res.data.data.submit=='1'){
          this.isShow=true;
          this.message="已通过";
          this.showbh=false;
        }else if (res.data.data.submit=='2'){
          this.isShow=true;
          this.message1="已驳回";
          this.showtg=false;
        }
      }).catch(err => {
        console.log(err);
      })
    },

    // 返回
    goBack() {
      this.$router.go(-1);
    },

    // 提交同意
    submitAgree() {
      this.show=false;
      this.$https.post('/mobiles/isAgreeMaintain', {
        nowUser:this.nowUser,
        id:this.id,
      }).then(res => {
        res;
        Toast("已通过");
        this.getMaintainInfo();//找到对应的页面详情，及领导信息
      }).catch(err => {
        console.log(err)
      });
    },
    //驳回
    submitNotAgree() {
      this.show=true;
    },
    chargeBtn(action,done){
      if (action==='cancel'){
        done();
      }else if (action==='confirm'){
        this.show=false;
        this.$https.post('/mobiles/isAgreeMaintain', {
          nowUser:this.nowUser,
          id:this.id,
          reason:this.reason,
        }).then(res => {
          res;
          Toast("已驳回");
          this.getMaintainInfo();//找到对应的页面详情，及领导信息
        }).catch(err => {
          console.log(err)
        });
      }
    },

  },
};
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-items: center;
  margin: 0 auto;
  .el-form {
    padding-right: 10px;
    .el-form-item {
      .el-form-item__label {
        line-height: 16px;
      }
      margin-bottom: 5px;
    }
  }
}
</style>